﻿function readURL(input) {

    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#avatar').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}
function readURL2(input) {

    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#wallpaper').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}

$(document).ready(function () {
    //Menu fixed
    var header = document.getElementById('user-option-tab');
    var content = document.getElementById('user-option-content');
    var origOffsetY = header.offsetTop;
    function onScroll(e) {
        window.scrollY >= origOffsetY ? header.classList.add('fixed-top') :
                                      header.classList.remove('fixed-top');
        window.scrollY >= origOffsetY ? content.classList.add('margin-thop') :
                                      content.classList.remove('margin-thop');
    }
    document.addEventListener('scroll', onScroll);

    $("#fileUpload[role='file']").change(function () {
        readURL(this);
    });

    $("#changewallpaper").change(function () {
        readURL2(this);
    });

    $("#btn_edit_avatar_staff").on("click", function () {
        var img = document.getElementById("fileUpload").value;
        if (img != "") {
            var file_data = document.getElementById('fileUpload').files[0];
            if (file_data == null) return; // chưa chọn file
            var form_data = new FormData();
            form_data.append("fileUpload", file_data);
            $.ajax({
                url: '../ajax/asp/staff/upload_avatar.aspx',
                data: form_data,
                processData: false,
                contentType: false,
                type: 'POST',
                success: function (data) {
                    //$("#divTreeView").html(data);
                }
            });
        }
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                location.reload(true);
            }
        };
        xhttp.open("GET", "../ajax/asp/staff/edit_avatar.aspx?img=" + img, true);
        xhttp.send();
    });
    $("#btn_edit_wall_staff").on("click", function () {
        var img = document.getElementById("changewallpaper").value;
        if (img != "") {
            var file_data = document.getElementById('changewallpaper').files[0];
            if (file_data == null) return; // chưa chọn file
            var form_data = new FormData();
            form_data.append("changewallpaper", file_data);
            $.ajax({
                url: '../ajax/asp/staff/upload_banner.aspx',
                data: form_data,
                processData: false,
                contentType: false,
                type: 'POST',
                success: function (data) {
                    //$("#divTreeView").html(data);
                }
            });
        }
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                location.reload(true);
            }
        };
        xhttp.open("GET", "../ajax/asp/staff/edit_banner.aspx?img=" + img, true);
        xhttp.send();
    });

    $("#btn_edit_info_staff").on("click", function () {
        var fullname = document.getElementById("personal_fullname").value;
        var email = document.getElementById("personal_email").value;
        var day = document.getElementById("personal_day").value;
        var month = document.getElementById("personal_month").value;
        var year = document.getElementById("personal_year").value;
        var phone = document.getElementById("personal_phone").value;
        var city = document.getElementById("personal_city").value;

        var birthday = year + "-" + month + "-" + day;
        var sex = "1";
        var error = 0;
        if ($('#user-female').is(":checked"))
            sex = "0";

        if (fullname.length == "" || fullname.length < 6) {
            $("#error_mes_name").removeClass("w3-hide");
            document.getElementById("error_mes_name").innerHTML = "Họ và tên quá ngắn!";
            error = 1;
        }
        else {
            $("#error_mes_name").addClass("w3-hide");
        }
        if (email.length == "") {
            $("#error_mes_email").removeClass("w3-hide");
            document.getElementById("error_mes_email").innerHTML = "Email không được để trống!";
            error = 1;
        }
        else {
            var check = /@/;
            if (check.test(email) == false) {
                $("#error_mes_email").removeClass("w3-hide");
                document.getElementById("error_mes_email").innerHTML = "Định dạng email không chính xác!";
                error = 1;
            }
            else {
                var temp = email.split('@');
                if (temp.length > 2) {
                    $("#error_mes_email").removeClass("w3-hide");
                    document.getElementById("error_mes_email").innerHTML = "Định dạng email không chính xác!";
                    error = 1;
                } else {
                    if (temp[1].toLowerCase() != "gmail.com" && temp[1].toLowerCase() != "yahoo.com" && temp[1].toLowerCase() != "yahoo.com.vn" && temp[1].toLowerCase() != "aol.com" && temp[1].toLowerCase() != "outlook.com" && temp[1].toLowerCase() != "senquocte.com") {
                        $("#error_mes_email").removeClass("w3-hide");
                        document.getElementById("error_mes_email").innerHTML = "Email @" + temp[1] + " không tồn tại hoặc không hỗ trợ!";
                        error = 1;
                    }
                    else {
                        $("#error_mes_email").addClass("w3-hide");
                    }
                }
            }
        }
        if (error == 0) {
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                    location.reload(true);
                }
            };
            xhttp.open("GET", "../ajax/asp/staff/edit_info.aspx?name=" + fullname + "&email=" + email + "&birthday=" + birthday + "&sex=" + sex + "&city=" + city + "&phone=" + phone, true);
            xhttp.send();
        }

    });

    $("#personal_month").on("change", function () {
        var day = document.getElementById("personal_day").value;
        var month = document.getElementById("personal_month").value;
        var year = document.getElementById("personal_year").value;
        if (month == 2) {
            if (day > 29) {
                if (year % 4 == 0)
                    document.getElementById("personal_day").value = 29;
                else
                    document.getElementById("personal_day").value = 28;
            }
        }
        else {
            if (month == 4 || month == 6 || month == 9 || month == 11) {
                if (day == 31) {
                    document.getElementById("personal_day").value = 30;
                }
            }
        }
    });

    $("#personal_day").on("change", function () {
        var day = document.getElementById("personal_day").value;
        var month = document.getElementById("personal_month").value;
        var year = document.getElementById("personal_year").value;

        if (month == 2 && day > 28) {
            if (year % 4 == 0)
                document.getElementById("personal_day").value = 29;
            else
                document.getElementById("personal_day").value = 28;
        }
        else {
            if (month == 4 || month == 6 || month == 9 || month == 11) {
                if (day == 31) {
                    document.getElementById("personal_day").value = 30;
                }
            }
        }
    });

    $("#personal_year").on("change", function () {
        var day = document.getElementById("personal_day").value;
        var month = document.getElementById("personal_month").value;
        var year = document.getElementById("personal_year").value;

        if (year % 4 == 0) {
            if (month == 2 && day > 29)
                document.getElementById("personal_day").value = 29;
        }
        else {
            if (month == 2 && day > 28)
                document.getElementById("personal_day").value = 28;
        }
    });

    $("#personal_province").on("change", function () {
        var id = document.getElementById("personal_province").value;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("personal_city").innerHTML = xhttp.responseText;
            }
        };
        xhttp.open("GET", "../ajax/asp/staff/get_city.aspx?id=" + id, true);
        xhttp.send();
    });

    $("#btn_get_time").on("click", function () {
        var month = document.getElementById("hour-month").value;
        var year = document.getElementById("hour-year").value;
        var id = document.getElementById("id_staff").innerHTML;

        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("tbl_worked").innerHTML = xhttp.responseText;
            }
        };
        xhttp.open("GET", "../ajax/asp/staff/time_worked.aspx?id=" + id + "&month=" + month + "&year=" + year, true);
        xhttp.send();
    });

    $(".btn_edited_work").on("click", function () {
        if ($(".edited").length) {
            var week = document.getElementById("work-week").value;
            var row = document.getElementsByClassName("row_work");
            var edited = "";
            for (var i = 0; i < row.length; i++) {
                if (row[i].getElementsByClassName("edited").length) {
                    edited += week + "_";
                    edited += row[i].getElementsByClassName("row_id")[0].innerHTML;
                    edited += "_";
                    edited += row[i].getElementsByClassName("manager_id")[0].innerHTML;
                    edited += "_";
                    for (var j = 0; j < 8; j++) {
                        if (row[i].getElementsByClassName("work")[j].getElementsByClassName("edited").length) {
                            edited += row[i].getElementsByClassName("work")[j].getElementsByClassName("edited")[0].value;
                            edited += "|";
                        }
                        else
                            edited += "|";

                    }
                    edited += ",";
                }
            }

            $.post("../ajax/asp/staff/working.aspx", { "edited": edited });

            document.getElementById("success_content").innerHTML = "Thay đổi đã được lưu";
            document.getElementById("success-modal").style.display = "block";
            setTimeout('$("#success-modal").fadeOut()', 3000);
        }
        else {
            alert("Lịch làm việc không thay đổi");
        }
    });

    $(".btn_add_working_form").on("click", function () {
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("lichLamViecMoi").innerHTML = xhttp.responseText;
            }
        };
        xhttp.open("GET", "../ajax/asp/staff/add_working_form.aspx", true);
        xhttp.send();
    });

    $(".btn_add_working").on("click", function () {
        var row = document.getElementsByClassName("add_working");
        var add_work = "";
        for (var i = 0; i < row.length; i++) {
            add_work += row[i].getElementsByClassName("txt_manager_id")[0].innerHTML;
            add_work += "_";
            for (var j = 0; j < row[i].getElementsByClassName("add_work").length; j++) {
                add_work += row[i].getElementsByClassName("add_work")[j].value.trim();
                add_work += "|";
            }
            add_work += ",";
        }

        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                location.reload(true);
            }
        };
        xhttp.open("GET", "../ajax/asp/staff/add_working.aspx?add_work=" + add_work, true);
        xhttp.send();
    });

    $("#work-year").on("change", function () {
        var year = document.getElementById("work-year").value;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("work-week").innerHTML = xhttp.responseText;
            }
        };
        xhttp.open("GET", "../ajax/asp/staff/get_week.aspx?year=" + year, true);
        xhttp.send();
    });

    $("#btn_change_pass").on("click", function () {
        var newpass = document.getElementById("txt_newpass").value;
        var oldpass = document.getElementById("txt_oldpass").value;
        var repass = document.getElementById("txt_repass").value;

        if (newpass == "" || oldpass == "" || repass == "") {
            document.getElementById("messenge_pass").innerHTML = "Thông tin nhập vào chưa đầy đủ";
        } else {
            if (repass != newpass) {
                document.getElementById("messenge_pass").innerHTML = "Nhập lại mật khẩu không đúng";
            }
            else {
                if (newpass.length < 6) {
                    document.getElementById("messenge_pass").innerHTML = "Mật khẩu mới quá ngắn";
                }
                else {
                    var xhttp;
                    xhttp = new XMLHttpRequest();
                    xhttp.onreadystatechange = function () {
                        if (xhttp.readyState == 4 && xhttp.status == 200) {
                            document.getElementById("change_pass").innerHTML = xhttp.responseText;
                        }
                    };
                    xhttp.open("GET", "../ajax/asp/staff/edit_pass.aspx?newpass=" + newpass + "&oldpass=" + oldpass, true);
                    xhttp.send();
                }
            }
        }
    });

    $("#ps-notice-list li").click(function () {
        $("#ps-notice-list li").removeClass("w3-teal");
        $(this).addClass("w3-teal");
        $("#create-notice-form").css("display", "none");
        $("#edit-notice-form").css("display", "block");
        document.getElementById("edit-notice-form").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
        var id = $(this).val();
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("edit-notice-form").innerHTML = xhttp.responseText;
                $('.ss-check-room').click(function () {
                    if ($(this).is(':checked')) {
                        $(this).parent().parent().find(".ss-check-member").prop("checked", true);
                    }
                    else {
                        $(this).parent().parent().find(".ss-check-member").prop("checked", false);
                    }
                });
                $(".ss-check-member").click(function () {
                    var tong = $(this).parent().parent().parent().find(".ss-check-member").length;
                    var child = this.parentElement.parentElement.parentElement.getElementsByClassName("ss-check-member");
                    var count = 0;
                    if ($(this).is(":checked")) {
                        for (var i = 0; i < child.length; i++) {
                            if (child[i].checked)
                                count++;
                        }
                        if (count == tong)
                            $(this).parent().parent().parent().parent().find(".ss-check-room").prop("checked", true);
                    }
                    else {
                        $(this).parent().parent().parent().parent().find(".ss-check-room").prop("checked", false);
                    }
                });
                tinymce.remove('textarea#txt_edit_notice_content');
                tinymce.init({
                    selector: 'textarea#txt_edit_notice_content',
                    height: 300,
                    width: '85%',
                    plugins: [
                      'advlist autolink lists link image charmap print preview anchor',
                      'searchreplace visualblocks code fullscreen furigana ',
                      'insertdatetime media table contextmenu paste code',
                      'textcolor'
                    ],
                    fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
                    toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'

                });
                
            }
        };
        xhttp.open("GET", "../ajax/asp/Notification/notification_edit_form.aspx?id=" + id, true);
        xhttp.send();
    });
    $(".create-notice-btn").click(function () {
        $("#ps-notice-list li").removeClass("w3-teal");
        $("#create-notice-form").css("display", "block");
        $("#edit-notice-form").css("display", "none");
    })
    //tiny-mce
    tinymce.remove('textarea#txt_add_notice_content');
    tinymce.init({
        selector: 'textarea#txt_add_notice_content',
        height: 300,
        width: '85%',
        plugins: [
          'advlist autolink lists link image charmap print preview anchor',
          'searchreplace visualblocks code fullscreen furigana ',
          'insertdatetime media table contextmenu paste code',
          'textcolor'
        ],
        fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
        toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'

    });
    $('.ss-check-room').click(function () {
        if ($(this).is(':checked')) {
            $(this).parent().parent().find(".ss-check-member").prop("checked", true);
        }
        else {
            $(this).parent().parent().find(".ss-check-member").prop("checked", false);
        }
    });
    $(".ss-check-member").click(function () {
        var tong = $(this).parent().parent().parent().find(".ss-check-member").length;
        var child = this.parentElement.parentElement.parentElement.getElementsByClassName("ss-check-member");
        var count = 0;
        if ($(this).is(":checked")) {
            for (var i = 0; i < child.length; i++) {
                if (child[i].checked)
                    count++;
            }
            if (count == tong)
                $(this).parent().parent().parent().parent().find(".ss-check-room").prop("checked", true);
        }
        else {
            $(this).parent().parent().parent().parent().find(".ss-check-room").prop("checked", false);
        }
    });
});
function view_working() {
    var id = document.getElementById("work-week").value;
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("lichLamViec").innerHTML = xhttp.responseText;
            //$(".work").dblclick(function () {
            //    if (!$(this).hasClass("edited")) {
            //        var context = this.innerHTML;
            //        this.innerHTML = "<input class='edited' type='text' value = '" + context + "'/>";
            //    }
            //});
        }
    };
    xhttp.open("GET", "../ajax/asp/staff/view_working.aspx?id=" + id, true);
    xhttp.send();
}

function openuser(evt, cityName) {
    var i, x, tablinks;
    x = document.getElementsByClassName("city");
    for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablink");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" w3-teal", "");
    }
    document.getElementById(cityName).style.display = "block";
    evt.currentTarget.className += " w3-teal";
}

function ss_open_author_list(that) {
    if ($(that).parent().parent().hasClass("opened")) {
        $(that).removeClass("fa-rotate-90");
        $(that).parent().parent().find(".ss-author-member-list").animate({ height: "toggle" }, "fast");
        $(that).parent().parent().removeClass("opened");
    }
    else {
        $(that).addClass("fa-rotate-90");
        $(that).parent().parent().addClass("opened");
        $(that).parent().parent().find(".ss-author-member-list").animate({ height: "toggle" }, "fast");
    }
}
function open_manager_list(id) {
    document.getElementById("role_show_manager_area").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("role_show_manager_area").innerHTML = xhttp.responseText;
            $('.ss-check-room').click(function () {
                if ($(this).is(':checked')) {
                    $(this).parent().parent().find(".ss-author-member-list").find(".ss-check-member").prop("checked", true);
                }
                else {
                    $(this).parent().parent().find(".ss-author-member-list").find(".ss-check-member").prop("checked", false);
                }
            });
            $(".ss-check-member").click(function () {
                var tong = $(this).parent().parent().parent().find(".ss-check-member").length;
                var child = this.parentElement.parentElement.parentElement.getElementsByClassName("ss-check-member");
                var count = 0;
                if ($(this).is(":checked")) {
                    for (var i = 0; i < child.length; i++) {
                        if (child[i].checked)
                            count++;
                    }
                    if (count == tong)
                        $(this).parent().parent().parent().parent().find(".ss-check-room").prop("checked", true);
                }
                else {
                    $(this).parent().parent().parent().parent().find(".ss-check-room").prop("checked", false);
                }
            });
        }
    };
    xhttp.open("GET", "../ajax/asp/staff/role_load_manager.aspx?id=" + id, true);
    xhttp.send();
}
function btn_check_role(id) {
    var accept = "";
    var manager = document.getElementById("role_show_manager_area").getElementsByClassName("ss-check-member");
    for (var i = 0; i < manager.length; i++) {
        if (manager[i].checked) {
            accept += manager[i].value;
            accept += ",";
        }
    }
    $.post("../ajax/asp/staff/role_accept_manager.aspx", { "id": id, "accept": accept });
    document.getElementById("success_content").innerHTML = "Thay đổi đã được lưu";
    document.getElementById("success-modal").style.display = "block";
    setTimeout('$("#success-modal").fadeOut()', 3000);
}

function btn_save_edited(id) {
    var manager = document.getElementById("edit-notice-form").getElementsByClassName("ss-check-member");
    var title = document.getElementById("edit-notice-form").getElementsByClassName("txt_notice_title")[0].value;
    var content = tinyMCE.get("txt_edit_notice_content").getContent();
    var accept = "";
    for (var i = 0; i < manager.length; i++) {
        if (manager[i].checked) {
            accept += manager[i].value;
            accept += ",";
        }
    }
    if (title == "")
    {
        document.getElementById("error_content").innerHTML = "Tiêu đề không được để trống";
        document.getElementById("success-modal").style.display = "block";
        setTimeout('$("#success-modal").fadeOut()', 3000);
    }
    else
    {
        if(content.length<5)
        {
            document.getElementById("error_content").innerHTML = "Nội dung thông báo quá ngắn";
            document.getElementById("success-modal").style.display = "block";
            setTimeout('$("#success-modal").fadeOut()', 3000);
        }
        else
        {
            $.post("../ajax/asp/notification/notification_edited.aspx", { "id": id, "title": title, "content": content, "accept": accept });
            document.getElementById("notification-" + id).innerHTML = title;
            document.getElementById("success_content").innerHTML = "Thông báo đã được lưu thành công";
            document.getElementById("success-modal").style.display = "block";
            setTimeout('$("#success-modal").fadeOut()', 3000);
        }
    }
    
}

function btn_notice_resend(id) {
    var manager = document.getElementById("edit-notice-form").getElementsByClassName("ss-check-member");
    var title = document.getElementById("edit-notice-form").getElementsByClassName("txt_notice_title")[0].value;
    var content = tinyMCE.get("txt_edit_notice_content").getContent();
    var accept = "";
    for (var i = 0; i < manager.length; i++) {
        if (manager[i].checked) {
            accept += manager[i].value;
            accept += ",";
        }
    }
    if (title == "") {
        document.getElementById("error_content").innerHTML = "Tiêu đề không được để trống";
        document.getElementById("success-modal").style.display = "block";
        setTimeout('$("#success-modal").fadeOut()', 3000);
    }
    else {
        if (content.length < 5) {
            document.getElementById("error_content").innerHTML = "Nội dung thông báo quá ngắn";
            document.getElementById("success-modal").style.display = "block";
            setTimeout('$("#success-modal").fadeOut()', 3000);
        }
        else {
            $.post("../ajax/asp/notification/notification_resend.aspx", { "id": id, "title": title, "content": content, "accept": accept });
            document.getElementById("notification_seen_area").innerHTML = "";
            document.getElementById("notification-" + id).innerHTML = title;
            document.getElementById("success_content").innerHTML = "Thông báo đã được gửi lại";
            document.getElementById("success-modal").style.display = "block";
            setTimeout('$("#success-modal").fadeOut()', 3000);
        }
    }
}
function btn_notice_del(id) {
    document.getElementById("del_notification").style.display = "block";
    document.getElementById("del_notice").innerHTML = id;
}

function btn_accept_notice_del()
{
    var id = document.getElementById("del_notice").innerHTML;
    document.getElementById("edit-notice-form").innerHTML = "";
    $("#notification-" + id).remove();
    document.getElementById("del_notification").style.display = "none";

    $.post("../ajax/asp/notification/notification_delete.aspx", { "id": id });
    document.getElementById("success_content").innerHTML = "Thông báo đã được xóa";
    document.getElementById("success-modal").style.display = "block";
    setTimeout('$("#success-modal").fadeOut()', 3000);
}

function btn_add_notice() {
    var accept="";
    var manager = document.getElementById("create-notice-form").getElementsByClassName("ss-check-member");
    var title = document.getElementById("create-notice-form").getElementsByClassName("txt_notice_title")[0].value;
    var content = tinyMCE.get("txt_add_notice_content").getContent();

    for (var i = 0; i < manager.length; i++) {
        if (manager[i].checked) {
            accept += manager[i].value;
            accept += ",";
        }
    }
    if (title == "") {
        document.getElementById("error_content").innerHTML = "Tiêu đề không được để trống";
        document.getElementById("success-modal").style.display = "block";
        setTimeout('$("#success-modal").fadeOut()', 3000);
    }
    else {
        if (content.length < 5) {
            document.getElementById("error_content").innerHTML = "Nội dung thông báo quá ngắn";
            document.getElementById("success-modal").style.display = "block";
            setTimeout('$("#success-modal").fadeOut()', 3000);
        }
        else {
            $.post("../ajax/asp/notification/notification_add.aspx", { "title": title, "content": content, "accept": accept });
            document.getElementById("success_content").innerHTML = "Thông báo đã được gửi";
            document.getElementById("success-modal").style.display = "block";
            setTimeout('$("#success-modal").fadeOut()', 3000);
            $("#create-notice-form").css("display", "none");
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                    document.getElementById("ps-notice-list").innerHTML = xhttp.responseText;
                    $("#ps-notice-list li").click(function () {
                        $("#ps-notice-list li").removeClass("w3-teal");
                        $(this).addClass("w3-teal");
                        $("#create-notice-form").css("display", "none");
                        $("#edit-notice-form").css("display", "block");
                        document.getElementById("edit-notice-form").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
                        var id = $(this).val();
                        var xhttp;
                        xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                            if (xhttp.readyState == 4 && xhttp.status == 200) {
                                document.getElementById("edit-notice-form").innerHTML = xhttp.responseText;
                                $('.ss-check-room').click(function () {
                                    if ($(this).is(':checked')) {
                                        $(this).parent().parent().find(".ss-check-member").prop("checked", true);
                                    }
                                    else {
                                        $(this).parent().parent().find(".ss-check-member").prop("checked", false);
                                    }
                                });
                                $(".ss-check-member").click(function () {
                                    var tong = $(this).parent().parent().parent().find(".ss-check-member").length;
                                    var child = this.parentElement.parentElement.parentElement.getElementsByClassName("ss-check-member");
                                    var count = 0;
                                    if ($(this).is(":checked")) {
                                        for (var i = 0; i < child.length; i++) {
                                            if (child[i].checked)
                                                count++;
                                        }
                                        if (count == tong)
                                            $(this).parent().parent().parent().parent().find(".ss-check-room").prop("checked", true);
                                    }
                                    else {
                                        $(this).parent().parent().parent().parent().find(".ss-check-room").prop("checked", false);
                                    }
                                });
                                tinymce.remove('textarea#txt_edit_notice_content');
                                tinymce.init({
                                    selector: 'textarea#txt_edit_notice_content',
                                    height: 300,
                                    width: '85%',
                                    plugins: [
                                      'advlist autolink lists link image charmap print preview anchor',
                                      'searchreplace visualblocks code fullscreen furigana ',
                                      'insertdatetime media table contextmenu paste code',
                                      'textcolor'
                                    ],
                                    fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
                                    toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'

                                });

                            }
                        };
                        xhttp.open("GET", "../ajax/asp/Notification/notification_edit_form.aspx?id=" + id, true);
                        xhttp.send();
                    });
                }
            };
            xhttp.open("GET", "../ajax/asp/Notification/notification_load_list.aspx", true);
            xhttp.send();
            
        }
    }
}

function btn_create_notice() {
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("create-notice-form").innerHTML = xhttp.responseText;
            tinymce.remove('textarea#txt_add_notice_content');
            tinymce.init({
                selector: 'textarea#txt_add_notice_content',
                height: 300,
                width: '85%',
                plugins: [
                  'advlist autolink lists link image charmap print preview anchor',
                  'searchreplace visualblocks code fullscreen furigana ',
                  'insertdatetime media table contextmenu paste code',
                  'textcolor'
                ],
                fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
                toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'

            });
            $('.ss-check-room').click(function () {
                if ($(this).is(':checked')) {
                    $(this).parent().parent().find(".ss-check-member").prop("checked", true);
                }
                else {
                    $(this).parent().parent().find(".ss-check-member").prop("checked", false);
                }
            });
            $(".ss-check-member").click(function () {
                var tong = $(this).parent().parent().parent().find(".ss-check-member").length;
                var child = this.parentElement.parentElement.parentElement.getElementsByClassName("ss-check-member");
                var count = 0;
                if ($(this).is(":checked")) {
                    for (var i = 0; i < child.length; i++) {
                        if (child[i].checked)
                            count++;
                    }
                    if (count == tong)
                        $(this).parent().parent().parent().parent().find(".ss-check-room").prop("checked", true);
                }
                else {
                    $(this).parent().parent().parent().parent().find(".ss-check-room").prop("checked", false);
                }
            });
        }
    };
    xhttp.open("GET", "../ajax/asp/notification/notification_add_form.aspx", true);
    xhttp.send();
}